<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>《万兔洗车》品鉴会-官方报名通道</title>
    <link href="/favicon.ico" rel="icon">
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="名额有限 先到先得" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="__STATICADMIN__layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="__STATICADMIN__css/style.css" rel="stylesheet" type="text/css" />
    <style>
        .plus-minus .layui-input-block {
            position: relative;
        }

        .plus-minus input {
            position: absolute;
            top: 0px;
            left: 0px;
            height: 36px;
            line-height: 36px;
            text-align: center;
        }

        .plus-minus button:nth-of-type(1) {
            position: absolute;
            top: 0px;
            left: 0px;
            height: 100%;
        }

        .plus-minus button:last-child {
            position: absolute;
            top: 0px;
            right: 0px;
            height: 100%;
        }

        .iziToast-wrapper {
            top: 30% !important
        }

        .fb_cart {
            padding-top: 2px;
            padding-bottom: 8px;
            border-top: 5px solid #f16e04;
            background-size: 10px;
            border-top-color: #a78970
        }

        .fb_cartTitle {
            position: relative;
            height: 43px;
            padding-left: 30px;
            line-height: 43px;
            font-size: 16px;
            border-top: 1px solid #f16e04;
            border-bottom: 1px solid #f5f5f5;
            color: #a78970;
            background-color: #fefefd;
        }

        .fb_cartTable {
            padding: 8px;
            padding-top: 0;
        }

        .fb_cartTh {
            display: display;
            height: 35px;
            padding: 0 10px;
            line-height: 35px;
            font-size: 14px;
            color: #666;
        }

        .fb_cartTd {
            display: inline-block;
            float: left;
            height: 100%;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .name {
            width: 50%
        }

        .quantity {
            width: 20%;
        }

        .subTotal {
            width: 30%;
        }

        .fb_cartCommodity {
            display: flex;
            height: 30px;
            padding: 0 10px;
            line-height: 30px;
            ;
        }

        .fb_cart_content {
            background-color: rgba(167, 137, 112, .05);
            border: 1px solid #f3d3bd;
        }
    </style>
</head>

<body style="background-color: #fdfdfe;" onload="changevalue(1)">
    <div style="max-width: 800px;margin:auto">
        <div style="text-align: center;"><img src="/wechat/banner.jpg" style="width: 100%;height: 300px;"></div>
        <div class="layui-fluid">
            <div class="layui-form-item" style="text-align:justify;color:#666666;padding:10px 0;line-height: 25px;">
                {$zscs.desc|raw|default=''}
            </div>
            <form action="{:url()}" class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>姓名
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="name" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" placeholder="请填写姓名">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>手机号(<span style="color: red;">同手机号报名一次</span>)
                    </div>
                    <div class="layui-form-item">
                        <input type="number" name="mobile" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" placeholder="请填写手机号">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>年龄
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="age" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" placeholder="请填写年龄">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>公司
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="gongsi" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="无" placeholder="请填写公司">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>车牌号
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="chepaihao" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" placeholder="请填写车牌号，如湘A88888">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>职位
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="zhiwei" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="无" placeholder="请填写职位">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>意向合作的区域
                    </div>
                    <div class="layui-form-item" style="color:#666">比如：长沙市:芙蓉区,岳麓区</div>
                    <div class="layui-form-item">
                        <input type="text" name="yxhz" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" placeholder="请填写意向合作的区域">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>赠送房型
                    </div>
                    <div class="layui-form-item" style="color:#666">一单位一间</div>
                    <div class="layui-form-item">
                        <input type="radio" name="zsfxs" value="1" title="标准间" checked>
                        <input type="radio" name="zsfxs" value="2" title="大床房">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red">* </font>参会费用办理
                    </div>
                    <div class="layui-form-item">
                        {if !empty($zscs.param)}
                        {foreach $zscs.param as $k => $v}
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md6 jsm">
                            <div style="width: 90%;border:1px dotted #d5d5d5;">
                                {if $k == 0}
                                <img src="/wechat/580rcq.jpg" style="width: 100%;height: 140px;">
                                {else}
                                <img src="/wechat/1280rcq.jpg" style="width: 100%;height: 140px;">
                                {/if}
                                <div style="margin:5px 0"><span
                                        style="font-size: 16px;padding:0 10px;font-weight: bold;">{$v.title}</span>
                                </div>
                                {if $k == 0}
                                <div style="margin:5px 0"><span style="padding:15px 10px;font-size: 14px;color:#999">限
                                        {$v.number}名</span></div>
                                {else}
                                <div style="margin:5px 0"><span
                                        style="padding:15px 10px;font-size: 14px;color:#999">--</span></div>
                                {/if}
                                <div>
                                    <div style="width: 40%;float: left;margin: auto;padding:10px 0"><span
                                            style="height:36px;line-height:36px;font-size: 16px;color:#2d91d9;font-weight: bold;text-align: center;">￥<span>{$v.price}</span>
                                    </div>
                                    <div style="width: 60%;float: left;">
                                        <div class="plus-minus" style="padding:10px 3px">
                                            <div class="layui-input-block" style="margin-left:0">
                                                {if $v.number > 0 && $k == 0}
                                                <input type="number" value="1" name="num[{$k}]" onChange="changevalue()"
                                                    lay-filter="go" data-step="1" data-price="{$v.price}"
                                                    data-maxvalue="{$v.xgnumber}" data-title="{$v.title}"
                                                    data-nnumber="{$v.number}" data-minvalue="0" lay-verify="required"
                                                    autocomplete="off" class="layui-input num" readonly>
                                                {elseif $zscs.param[0]['number'] <=0 && $k==1} <input type="number"
                                                    value="1" name="num[{$k}]" onChange="changevalue()" lay-filter="go"
                                                    data-step="1" data-title="{$v.title}" data-price="{$v.price}"
                                                    data-maxvalue="{$v.xgnumber}" data-nnumber="{$v.number}"
                                                    data-minvalue="0" lay-verify="required" autocomplete="off"
                                                    class="layui-input num" readonly>
                                                    {else}
                                                    <input type="number" value="0" name="num[{$k}]"
                                                        onChange="changevalue()" lay-filter="go" data-step="1"
                                                        data-title="{$v.title}" data-price="{$v.price}"
                                                        data-maxvalue="{$v.xgnumber}" data-nnumber="{$v.number}"
                                                        data-minvalue="0" lay-verify="required" autocomplete="off"
                                                        class="layui-input num" readonly>
                                                    {/if}

                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div style="clear: both;"></div>

                            </div>
                        </div>
                        {/foreach}
                        {/if}
                    </div>
                </div>
                <div class="cartWrapper" style="background-color:#FAFBFC;">
                    <div class="fb_cart fb_cart_mms">
                        <div class="fb_cartTitle"><span>收银台</span>
                        </div>
                        <div class="fb_cartTable">
                            <div class="fb_cartHeader">
                                <div class="fb_cartTh"><span class="fb_cartTd name">项目名称</span><span
                                        class="fb_cartTd quantity">数量</span><span class="fb_cartTd subTotal">小计</span>
                                </div>
                            </div>
                            <ul class="fb_cart_content">
                            </ul>
                        </div>
                        <div class="layui-form-item">
                            <input type="radio" name="payment" value="1" title="微信支付(仅微信内可用)">
                            <input type="radio" name="payment" value="2" title="支付宝支付">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <font color="red"></font>需支付
                        <span style="font-size: 18px;color:#f16e04;font-weight: bold;">￥<span id="total">0</span></span>
                    </div>
                </div>
                <div class="layui-footer layui-form-item layui-center ">
                    <button class="layui-btn layui-btn-lg" style="width: 90%;" lay-filter="submitIframe" type="button"
                        lay-submit>提交参会信息</button>
                </div>
            </form>
        </div>
        <script src="__STATICADMIN__layui/layui.js"></script>
        <script src="__STATICADMIN__js/common.js"></script>
        <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script>
            function changevalue($num) {
                layui.define(['layer', 'form'], function (exports) {
                    var $ = layui.$
                    var form = layui.form;
                    var total = 0;
                    if ($num == 1) {
                        var stro = JSON.parse(localStorage.getItem('config'));
                        layui.$.each(stro, function (m, obj) {
                            if (m == 'zsfxs') {
                                layui.$("input[name='" + m + "'][value=" + obj + "]").attr('checked', 'true');
                            } else if (m == 'num[0]' || m == 'num[1]' || m == 'num[2]' || m == 'num[3]' || m == 'num[4]' || m == 'num[5]' || m == 'payment') {
                            } else {
                                layui.$("input[name='" + m + "']").val(obj);
                            }
                        });
                        form.render();
                    }
                    var html = '';
                    $('.num').each(function () {
                        var num = 0;
                        var price = 0;
                        num = $(this).val();
                        price = $(this).data('price');
                        title = $(this).data('title');
                        total += num * price;
                        if (num > 0) {
                            html += '<li class="fb_cartCommodity"><span class="fb_cartTd name">' + title + '</span><span class="fb_cartTd quantity">×' + num + '</span><span class="fb_cartTd subTotal"><span class="bb-price bb-price-lower-decimal bb-price-lower-symbol"><span class="bb-pr-symbol">¥</span><span class="bb-pr-inpart">' + num * price + '</span></span></span></li>';
                        }
                    });
                    total = total.toFixed(2);
                    $('#total').text(total);
                    $('.fb_cart_content').html(html);
                });
            }
        </script>
        <script>
            layui.use(['admin', 'layer', 'table', 'form'], function () {
                var admin = layui.admin;
                var layer = layui.layer;
                var table = layui.table;        // 表格
                var form = layui.form;
                var config = {};
                // 监听权限提交
                form.on("submit(submitIframe)", function (post) {
                    localStorage.setItem('config', JSON.stringify(post.field));
                    post.field.openid = localStorage.getItem('openid');
                    // 开始POST提交数据
                    layui.$.post("{:url('other/ruchang')}", post.field, function (res) {
                        if (res.code == 0) {
                            //微信支付
                            if (post.field.payment == 1) {
                                WeixinJSBridge.invoke('getBrandWCPayRequest', {
                                    "appId": res.data.appid,   //公众号ID，由商户传入    
                                    "timeStamp": res.data.timeStamp,   //时间戳，自1970年以来的秒数    
                                    "nonceStr": res.data.nonceStr,      //随机串    
                                    "package": res.data.package,
                                    "signType": res.data.signType,     //微信签名方式：    
                                    "paySign": res.data.paySign //微信签名
                                }, function (res) {
                                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                                        // 使用以上方式判断前端返回,微信团队郑重提示：
                                        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                                        // layer.alert('支付成功');
                                        location.reload();
                                    }
                                    if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                        // 使用以上方式判断前端返回,微信团队郑重提示：
                                        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                                        layer.alert('您已取消支付,锁定名额一分钟后将释放');
                                    }

                                });
                                if (typeof WeixinJSBridge == "undefined") {
                                    if (document.addEventListener) {
                                        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                                    } else if (document.attachEvent) {
                                        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                                    }
                                } else {
                                    WeixinJSBridge.call("closeWindow");
                                }
                            }
                            //支付宝支付
                            if (post.field.payment == 2) {
                                if (res.data.payment_id) {
                                    layui.$(function () {
                                        var url = "{:url('other/aliypay')}";
                                        location.href = url + '?paymentid=' + res.data.payment_id + '&url=other/ruchang';
                                        //location.href = res.data.url;
                                    });
                                } else {
                                    layer.msg('操作错误,请重试');

                                }
                            }

                        } else if (res.code == 2) {
                            layer.alert(res.msg);
                        }
                        else {
                            layer.alert(res.msg);
                        }
                    }, 'json');

                    return false;
                })
            });
        </script>
        <script>
            layui.extend({
                common: 'minus'  //改为上方代码所在文件的路径
            }).use(['common'], function () {
                var common = layui.common;
                common.plusminus();
            })
        </script>

        <script>
            var url = "{:Env::get('app.api_url')}";
            var appid = "{:Config()['wechat1']['app_id']}";
            var openid = localStorage.getItem('openid');
            var fhopenid = "{$openid|default=''}";
            if (fhopenid) {
                localStorage.setItem('openid', fhopenid);
            }
            var is_weixin = (function () { return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1 })();
            if (is_weixin) {
                if (!openid) {
                    layui.$(function () {
                        location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=https://' + url + '/other/ruchang&response_type=code&scope=snsapi_base&target=other/ruchang';
                    });
                }
                layui.$("input[name='payment'][value=1]").attr('checked', 'true');
                // layui.$("input[name='payment'][value=2]").attr('disabled', 'true');
            } else {
                layui.$(function () {
                    layui.$("input[name='payment'][value=1]").attr('disabled', 'true');
                    layui.$("input[name='payment'][value=2]").attr('checked', 'true');
                    return false;
                });
            }
            wx.config({
                debug: false,
                appId: "{$share.appId|default=''}",
                timestamp: "{$share.timestamp|default=''}",
                nonceStr: "{$share.nonceStr|default=''}",
                signature: "{$share.signature|default=''}",
                jsApiList: [
                    'onMenuShareAppMessage',
                    'onMenuShareAppMessage'
                ]
            });
            wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                wx.onMenuShareAppMessage({
                    title: '《万兔洗车》品鉴会-官方报名通道',
                    desc: '名额有限  先到先得',
                    imgUrl: 'https://xcapi.tcwang888.com/wechat/banner.jpg',
                    trigger: function (res) {
                        // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
                        //alert('用户点击发送给朋友');
                    },
                    success: function (res) {
                        //alert('分享成功');
                    },
                    cancel: function (res) {
                        //alert('取消分享');
                    },
                    fail: function (res) {
                        alert(JSON.stringify(res));
                    }
                });
            });
            if (!window.localStorage) {
                console.log("浏览器不支持localstorage");
            } else {
                var config = JSON.parse(localStorage.getItem('config'));
                if (config.mobile) {
                    layui.$.post("{:url('other/ruchang')}", { mobile: config.mobile, istrue: 1 }, function (res) {
                        if (res.code == 0) {
                            layer.alert('手机号为' + config.mobile + '的用户您已报名成功');
                        }
                    });
                }
            }
        </script>
    </div>
</body>

</html>